﻿using AiQiuQuan.Sport.Model.Enums;
using AiQiuQuan.Sport.Core.Tool;
using System.Security.Cryptography;
using System.Text;

namespace AiQiuQuan.Sport.WebApi.Core
{
    /// <summary>
    /// tool
    /// </summary>
    public class Tool
    {
        /// <summary>
        /// 生成支付订单号:前2位为业务类型，不足前面补0
        /// </summary>
        public static string BuildPayOrderNo(BusinessTypeEnum businessType)
        {
            return $"{((int)businessType).ToString().PadLeft(2, '0')}{IdGenerator.Instance.GetNexId()}";
        }

        /// <summary>
        /// 单个数字转为大写数字，ex: 一
        /// </summary>
        /// <param name="number">1-9</param>
        public static string SingleNumberToChineseNumber(int number)
        {
            number = Math.Abs(number);
            switch (number)
            {
                case 1:
                    return "一";
                case 2:
                    return "二";
                case 3:
                    return "三";
                case 4:
                    return "四";
                case 5:
                    return "五";
                case 6:
                    return "六";
                case 7:
                    return "七";
                case 8:
                    return "八";
                case 9:
                    return "九";
            }

            return string.Empty;
        }

        /// <summary>
        /// 获取星期几
        /// </summary>
        public static string WeekName(DateTime date)
        {
            switch (date.DayOfWeek)
            {
                case DayOfWeek.Sunday:
                    return "星期日";
                case DayOfWeek.Monday:
                    return "星期一";
                case DayOfWeek.Tuesday:
                    return "星期二";
                case DayOfWeek.Wednesday:
                    return "星期三";
                case DayOfWeek.Thursday:
                    return "星期四";
                case DayOfWeek.Friday:
                    return "星期五";
                case DayOfWeek.Saturday:
                    return "星期六";
                default:
                    return "未知";
            }
        }

        /// <summary>
        /// 是否工作日
        /// </summary>
        public static bool IsWorkDay(DateTime date)
        {
            switch (date.DayOfWeek)
            {
                case DayOfWeek.Sunday:
                    return false;
                case DayOfWeek.Monday:
                    return true;
                case DayOfWeek.Tuesday:
                    return true;
                case DayOfWeek.Wednesday:
                    return true;
                case DayOfWeek.Thursday:
                    return true;
                case DayOfWeek.Friday:
                    return true;
                case DayOfWeek.Saturday:
                    return false;
                default:
                    return false;
            }
        }

        /// <summary>
        /// 转成MD5
        /// </summary>
        public static string ToMd5(string content)
        {
            var bytes = Encoding.UTF8.GetBytes(content);
            var array = MD5.Create().ComputeHash(bytes);
            var stringBuilder = new StringBuilder();
            foreach (var b in array)
            {
                stringBuilder.Append(b.ToString("X2"));
            }

            return stringBuilder.ToString();
        }
    }
}
